<template>
	<view >
		<!-- 搜索框 -->
		<view class="myview">
			<my-search @click="getmy"></my-search>
		</view>
		
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true" class="root">
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
			
		</swiper>
		<!-- 导航区 -->
		<view class="dh">
			<view v-for="(item,index) in navList" :key="index" @click="getfl(item.name)">
				<image :src="item.image_src"></image>
				
			</view>
		</view>
		<!-- 楼层标题图片区 -->
		<view class="">
			<view v-for="(item,index) in floorList" :key="index">
				<image :src="item.floor_title.image_src" class="lcimg"></image>
				<view class="Boxbt">
					<navigator class="letbt" :url="item.product_list[0].url" >
						 <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="ritbt">
					<navigator v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2 !==0" :url="item.product_list[i2].url">
						<image :src="item2.image_src" :style="{width:item2.image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 轮播画存放数据的数组
				swiperList:[],
				// 导航条的数组
				navList:[],
				// 楼层的数据
				 floorList:[],
			};
		},
		onLoad() {
			this.getSwiperList();
			this.getnavList();
			this.getfloorList();
		},
		methods:{
			// 获取轮播画数据的方法
		 	async getSwiperList(){
				// 发起请求
				const s= await uni.$http.get('/api/public/v1/home/swiperdata');
				console.log(s)
				// 请求失败
				if(s.data.meta.status !== 200) return uni.$showMsg();
				this.swiperList = s.data.message;
				console.log(s.data.message[1].image_src)
				uni.$showMsg('数据请求成功',1500)
			},
			// 获取导航条数据的方法
			async getnavList(){
				const {data:s} =await uni.$http.get('/api/public/v1/home/catitems');
				if(s.meta.status !==200) return uni.$showMsg();
				this.navList = s.message;
				console.log(this.navList)
			}
			,
			// 导航条跳转分类的方法
			getfl(item){
				if(item !== "分类") return;
				uni.switchTab({
					url:"/pages/classificAtion/classificAtion"
				})
			},
			// 楼层获取数据的方法
			async getfloorList(){
				const {data:s} =await uni.$http.get('/api/public/v1/home/floordata');
				if(s.meta.status !==200) return uni.$showMsg();
				// 通过双层forEach循环。处理URL地址
				s.message.forEach(floor =>{
					floor.product_list.forEach(prod =>{
						prod.url = '/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1];
					})
				})
				this.floorList = s.message;
				console.log('你好',this.floorList)
			},
			// 搜索的点击事件
			getmy(){
				uni.navigateTo({
					url:"../../subpkg/search/search"
				})
			}
		}
	}
</script>

<style lang="scss">
	.root{
		height: 305rpx;
		// border: 1px solid  #DD524D;
	}
	.swiper-item image{
		// height: 100%;
		width: 100%;
		background-position: center;
		background-size: 100%;
		background-repeat: no-repeat;
	}
	.swiper-item{
		height: 100%;
	}
	// image{
	// 	height: 100%;
	// }
	.dh{
		display: flex;
		justify-content: space-around;
		margin: 15rpx 0;
	}
	.dh image{
		width: 128rpx;
		height: 140rpx;
	}
	.lcimg{
		height: 60rpx;
		width: 100%;
		display: flex;
	}
	.Boxbt{
		display: flex;
		padding-left: 10rpx;
	}
	.ritbt{
		
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		
	}
	.myview{
		position: sticky;
		top:0;
		z-index: 999;
	}
	
</style>
